local public_line = {}

class.tgBtn = extends(class.button) {
    reload = true,
    new = function (parent,x,y,w,h)
        local panel = class.tgBtn:builder 
        {
            parent = parent,
            x = x,
            y = y,
            w = w,
            h = h,
        }
        return panel
    end,

    init = function (self)
        class.button.init(self)
        self:set_normal_image([[ReplaceableTextures\TeamColor\TeamColor15.blp]])

        self.icon = self:add_panel([[ReplaceableTextures\CommandButtons\BTNPriest.blp]],20,10,64,64)
        self.title = self:add_text('难度1',90,0,self.w,self.h/2,12,1)
        self.load = self:add_text('进度：1/9',90,self.h/2,self.w,self.h/2,12,7)
        
        self.highlight = self:add_panel([[UI\选中框.tga]],-5,-5,self.w+10,self.h+10)
        self.highlight:hide()
        return self
    end,
    set_data = function(self,skill)
        self.skill = skill
        if skill then
            if skill.tip==nil then
                local tips = {}
                local sum = 0
                for a,info in ipairs(skill) do
                    if info.open then
                        sum = sum + 1
                        tips[a] = ('|cff00ff00%s|r'):format(info.tip)
                    else
                        tips[a] = ('|cff999999%s|r'):format(info.tip)
                    end
                end
                skill.tip = table.concat(tips,'|n')
                skill.load = ('进度：%s/%s'):format(sum,#skill)
            end
            self.title:set_text(skill.name)
            self.load:set_text(skill.load)
            self:show()
        else
            self:hide()
        end
    end
}


--[面板]
class.save_ui3 = extends(class.panel) {
    reload = true,
    new = function (parent,x,y,w,h)
        local panel = class.save_ui3:builder 
        {
            parent = parent,
            x = x,
            y = y,
            w = w,
            h = h,
        }
        return panel
    end,
    init = function (self)
        class.panel.init(self)
        
        self.title = self:add_text('|cffffff00总通关|r',0,10,nil,30,16,5)

        --分割线
        self:add_panel([[ReplaceableTextures\TeamColor\TeamColor09.blp]],0,60,self.w,2)
        
        local w,h = 250,80
        local buttons = {}
        for a=1,10 do
            local x = ((a-1)%3) * (w+5) + 20
            local y = (math.ceil(a/3) - 1) * (h + 5) + 80
            local button = self:add_tgBtn(x,y,w,h)
            buttons[a] = button
        end
        self.buttons = buttons

        return self
    end,
        
    update = function(self)
        local player = ac.player.self
        local data = ac['通关存档'] or {}

        for a,button in ipairs(self.buttons) do
            local skill = data[a]
            button:set_data(skill)
        end
        
    end,

    on_button_mouse_enter = function(self,button)
        local skill = button.skill
        if skill then
            button:tooltip(skill.name,skill.tip,'bottom',400)
            --button:tooltip(skill:get_title(),skill:get_tip())
        end
    end,

}

-- local w,h = 1000,600
-- local ui = class.save_ui3:builder 
-- {
--     x = (1920 - w)/2,
--     y = 150,
--     w = w,
--     h = h,
-- }